import React, { useState, useEffect } from "react";

export const Hook1 = (props: any) => {
  // console.log('你好：' + props.zock);

  // 声明一个叫 “count” 的 state 变量。
  const [count, setCount] = useState(0);
  const [error, setError] = useState(null);
  const [list, setList] = useState([]);

  const countAdd = (): void => {
    setCount(count + 1);
  };

  useEffect(() => {
    fetch("https://www.mypep.cn/static/repository/expandManager/list.json")
      .then((res) => res.json())
      .then(
        (result) => {
          // console.log(result);
          setList(result.list);
        },
        (error) => {
          setError(error);
        }
      );
  }, []);

  if (error) {
    return <div>Error: {error}</div>;
  } else {
    return (
      <ul>
        {list.map((item, index) => (
          <li onClick={countAdd} key={index}>
            {item?.["title"]}
          </li>
        ))}
      </ul>
    );
  }
};
